<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <style>
        .item{
            float: left;
            border: 1px solid #eee;
        }
        .item img{
            width: 240px;
            vertical-align: bottom;
            padding: 5px;
        }
    </style>
</head>
<body>
    <div id="app"></div>
    <script>
        http();

        function http(){
            var url = "http://192.168.4.18:8000/more";
            $.ajax({
                url,
                success:res=>{
                    res.forEach(item=>{
                        var template = `
                        <div class="item">
                            <img src=${item.imageUrl}>
                        </div>
                        `
                        $("#app").append(template)
                    })
                    setTimeout(sortBox,100)
                    sortBox();
                }
            })
        }

        function sortBox(){
            var ww = $(window).width();
            var box = $(".item").outerWidth();
            var num = Math.floor(ww/box);
            var arr = [];
            $(".item").each((index,value)=>{
                if(index<num){
                    var height = $(value).outerHeight();
                    arr.push(height)
                }else{
                    var minHeight = Math.min(...arr);
                    var index = arr.indexOf(minHeight);
                    var offsetLeft = $(".item").eq(index).offset().left;
                    $(value).css({position:"absolute",left:offsetLeft,top:minHeight})
                    arr[index] = minHeight+$(value).outerHeight();
                }
            })

        }
    </script>
</body>
</html>